/*
 * @Author: 橘子
 * @Date: 2022-11-07 09:13:28
 * @Project_description:  权限校验
 * @Description: 代码是我抄的，不会也是真的
 */
import route from '@/router'

export default {
  bind(el, binding, vnode, oldVnode) {
    //获取指令传递的数组
    const { value } = binding
    return
    //获取当前页面给定的权限
    const roles = route.meta.roles

    console.log(roles)
    if (value && value instanceof Array) {
      if (value.length > 0) {
        const permissionRoles = value
        const hasPermission = roles.some(role => {
          return permissionRoles.includes(role)
        })
        //如果没有就把当前元素删除
        if (!hasPermission) {
          el.parentNode && el.parentNode.removeChild(el)
        }
      }
    } else {
      throw new Error(`v-auth="['add','edit']"`)
    }
  },
}
